#ifndef _MD5_H_
#define _MD5_H_

#pragma warning(disable:4786)

#include <string>
using namespace std;

//#include "LibUtility.h"
//class LIB_UTILITY_DLLAPI CMD5  
class CMD5
{
private:

	typedef unsigned long md5_uint32;

	struct MD5Context {
		md5_uint32 buf[4];
		md5_uint32 bits[2];
		unsigned char in[64];
	};

	void Init(struct MD5Context *context);
	void Update(struct MD5Context *context, unsigned char const *buf, unsigned len);
	void Final(unsigned char digest[16], struct MD5Context *context);
	void Transform(md5_uint32 buf[4], const unsigned char in[64]);

	inline md5_uint32 GetU32 (const unsigned char *addr)
	{
		return (((((unsigned long)addr[3] << 8) | addr[2]) << 8)
			| addr[1]) << 8 | addr[0];
	}

	inline void PutU32 (md5_uint32 data, unsigned char *addr)
	{
		addr[0] = (unsigned char)data;
		addr[1] = (unsigned char)(data >> 8);
		addr[2] = (unsigned char)(data >> 16);
		addr[3] = (unsigned char)(data >> 24);
	}


public:
	CMD5();
	~CMD5();

    string  ToMD5     (const string &str);
	string  ToHexaMD5 (const string &str);
	string	ToHexaMD5 (BYTE* pBuf, UINT nLength);
    wstring ToHexaMD5W(const wstring &strData);
};

#endif	// #ifndef _MD5_H_
